﻿
@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Index.cshtml";
}

<style>
    .gridPanel {
        padding: 0;
        border-top: 1px solid #dddddd;
        border-left: 1px solid #dddddd;
    }
</style>
<div class="topPanel">
    <div class="toolbar">
        <div class="btn-group">
            <a class="btn btn-primary" onclick="$.reload()"><span class="fa fa-refresh"></span></a>
        </div>
        <div class="btn-group">
            <a id="NF-add" authorize="yes" class="btn btn-primary" onclick="btn_add()">
                <i class="fa fa-plus"></i>新建
            </a>
        </div>
        <div class="btn-group">
            <a id="NF-edit" authorize="yes" class="btn btn-primary" onclick="btn_edit()">
                <i class="fa fa-pencil-square-o"></i>修改
            </a>
        </div>
        <div class="btn-group">
            <a id="NF-authorg" authorize="yes" class="btn btn-primary" onclick="btn_delete()">
                <i class="fa fa-trash-o"></i>删除
            </a>
        </div>
    </div>
    <div class="search">
        <table>
            <tr>
                <td>
                    <div class="input-group">
                        <input id="txt_keyword" type="text" class="form-control" placeholder="药库/药房" style="width: 180px;">
                        <span class="input-group-btn">
                            <button id="btn_search" type="button" class="btn  btn-primary"><i class="fa fa-search"></i></button>
                        </span>
                    </div>
                </td>
            </tr>
        </table>
    </div>
</div>
<div class="gridPanel">
    <table id="gridList"></table>
    <div id="RpListPage"></div>
</div>

<script>
    $(function () {
        //浏览器窗口调整大小时重新加载jqGrid的宽
        $(window).resize(function () {
            $("#gridList").setGridHeight($(window).height() - 120);
            initLayout("MyTabGrid");
        });
        //加载明细
        $("#gridList").dataGrid({
            postData: {},
            url: "/Dictionaries/GetFypzPagintionGridJson",
            height: $(window).height() - 120,
            colModel: [
                { label: "Id", name: "Id", align: "left", hidden: true },
                { label: "药库", name: "ykCode", autowidth: true, align: "left" },
                { label: "药房", name: "yfCode", autowidth: true, align: "left" },
                { label: "有效", name: "zt", autowidth: true, align: "center", formatter: function (cellvalue) { return cellvalue == "1" ? "<i class=\"fa fa-toggle-on\"></i>" : "<i class=\"fa fa-toggle-off\"></i>"; } },
                { label: '创建人', name: 'CreatorCode', autowidth: true, align: 'left' },
                { label: '创建时间', name: 'CreateTime', autowidth: true, align: 'left', formatter: "date", formatoptions: { srcformat: 'Y-m-d H:i:s', newformat: 'Y-m-d H:i:s' } },
                { label: '最后修改人', name: 'LastModifierCode', autowidth: true, align: 'left' },
                { label: '最后修改时间', name: 'LastModifyTime', autowidth: true, align: 'left', formatter: "date", formatoptions: { srcformat: 'Y-m-d H:i:s', newformat: 'Y-m-d H:i:s' } },
            ],
            rowNum: 10,
            pager: "#RpListPage",
            sortname: 'CreateTime desc',
            viewrecords: true,
        });
        //搜索按钮
        $("#btn_search").click(function () {
            $("#gridList").jqGrid('setGridParam', {
                postData: { keyword: $("#txt_keyword").val() }, page: 1
            }).trigger('reloadGrid');
        });
        //回车事件
        $('#txt_keyword').keydownEnterEvent(function () {
            $('#btn_search').trigger('click');
        })
    });
    function btn_add() {
        $.modalOpen({
            id: "Form",
            title: "新增",
            url: "/Dictionaries/FypzForm",
            width: "500px",
            height: "340px",
            callBack: function (iframeId) {
                $.currentWindow(iframeId).AcceptClick(function () {
                    $("#gridList").resetSelection();
                    $("#gridList").trigger("reloadGrid");
                });
            }
        });
    }

    function btn_edit() {
        var keyValue = $("#gridList").jqGridRowValue().Id;
        if (!!!keyValue) {
            $.modalAlert("请选中一条信息", 'warning');
            return;
        }
        $.modalOpen({
            id: "Form",
            title: "修改",
            url: "/Dictionaries/FypzForm?keyValue=" + keyValue,
            width: "500px",
            height: "340px",
            callBack: function (iframeId) {
                $.currentWindow(iframeId).AcceptClick(function () {
                    $("#gridList").resetSelection();
                    $("#gridList").trigger("reloadGrid");
                });
            }
        });
    }

    function btn_delete() {
        var keyValue = $("#gridList").jqGridRowValue().Id;
        if (!!!keyValue) {
            $.modalAlert("请选中一条信息", 'warning');
            return;
        }
        $.deleteForm({
            url: "/Dictionaries/DeleteFypzForm",
            param: { keyValue: keyValue },
            success: function () {
                $("#gridList").resetSelection();
                $("#gridList").trigger("reloadGrid");
            }
        });
    }
</script>